<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>组织机构树</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" href="/bsc/static/common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="/bsc/static/common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" href="/bsc/static/common/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="/bsc/static/css/personal.css" media="all">
</head>
<body bgcolor="red">
<section class="layui-larry-box">
			<div class="larry-personal">
				<div class="layui-tab">
				   <form action="" method="post">
						<div class="layui-inline">
							<div class="layui-input-inline">
								<input value="${user_name }" placeholder="请输入员工名称" class="layui-input search_input" name="user_name" type="text">
							</div>
							<a class="layui-btn search_btn">查询</a>
						</div>
						<div class="layui-inline">
							<a class="layui-btn layui-btn-normal newsAdd_btn">添加员工</a>
						</div>
				   </form>		
					<!-- 操作日志 -->
						<table class="layui-table">
							<colgroup>
								<col width="5%">
								<col width="9%">
								<col width="9%">
								<col width="9%">
								<col width="9%">
								<col width="9%">
								<col width="9%">
								<col width="9%">
								<col width="15%">
							</colgroup>
					<thead>
						<tr style="white-space:nowrap ;text-align:center">
							<th style="text-align:left;">编号</th>
							<th>用户账号</th>
							<th>用户名</th>
							<th>所属机构</th>
							<th>所属角色</th>
							<th>性别</th>
							<!-- <th>手机号</th> 
							<th>邮箱</th> -->
							<th>用户状态</th>
							<!-- <th>qq号</th>
							<th>微信号</th>
							<th>身份证号</th> -->
							<th>查看联系方式</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody class="news_content">
					    <c:if test="${empty listupd }">
					    <tr>
					       <td colspan="9">没有数据了</td>
					    </tr>
					    </c:if>
					    
						<c:forEach items="${listupd }" var="u" varStatus="s">
						<tr style="white-space:nowrap ;text-align:center"> 
						   <!--style="display: none;"隐藏  -->
						    <td hidden class="td">${u.user_id }</td>
							<td align="left">${s.index+1 }</td>
							<td>${u.account }</td>
							<td>${u.username }</td>
							<td>${u.dept.dept_name }</td>
							<td><div class="layui-inline">
								<c:if test="${empty u.role.role_name }">
							        <a class="layui-btn layui-btn-danger batchDel">点击添加</a>
							   </c:if>
							   <c:if test="${not empty u.role.role_name }">
							        <a class="layui-btn layui-btn-danger batchDel">${u.role.role_name }</a>
							   </c:if>
							</div></td>
							<td>${u.sex=='1'?'男':(u.sex=='2'?'女':'未知') }</td>
							<td hidden class="mobile" >${u.mobile }</td>
							<td hidden class="email" >${u.email }</td>
							<td>${u.status=='1'?'正常':(u.status=='2'?'停用':'锁定') }</td>
							<td hidden class="qq" >${u.qq }</td>
							<td hidden class="wechat" >${u.wechat }</td>
							<td hidden class="idno" >${u.idno }</td>
							<td>
								<a class="layui-btn layui-btn-normal layui-btn-mini news_collect"><i class="layui-icon"></i>查看联系方式</a>
							</td>
							<td> 
							    <c:if test="${u.status=='3' }">
							        <a class="layui-btn layui-btn-mini news_del" onclick="up('${u.user_id }','1','启用')" ><i class="iconfont icon-edit"></i> 启用</a>
							    </c:if>
							    <c:if test="${u.status=='2' }">
							        <a class="layui-btn layui-btn-mini news_del" onclick="up('${u.user_id }','1','启用')" ><i class="iconfont icon-edit"></i> 启用</a>
							        <a class="layui-btn layui-btn-danger layui-btn-mini news_del" onclick="up('${u.user_id }','3','锁定')" data-id="12" ><i class="layui-icon"></i>锁定</a>
							    </c:if>
							    <c:if test="${u.status=='1' }">
							        <a class="layui-btn layui-btn-danger layui-btn-mini news_del" onclick="up('${u.user_id }','2','停用')" data-id="12" ><i class="layui-icon"></i>  停用</a>
							        <a class="layui-btn layui-btn-danger layui-btn-mini news_del" onclick="up('${u.user_id }','3','锁定')" data-id="12" ><i class="layui-icon"></i>锁定</a>
							    </c:if>
							        
							</td> 
						</tr>
						</c:forEach>
					</tbody>
					</table>
                     <div class="larry-table-page clearfix">
				          <div id="page" class="page"></div>
			         </div>
</section>
<script type="text/javascript" src="/bsc/static/common/layui/layui.js"></script>
<script type="text/javascript" src="/bsc/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/bsc/static/common/bootstrap/js/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
	layui.use(['jquery','layer','element','laypage'],function(){
	      window.jQuery = window.$ = layui.jquery;
	      window.layer = layui.layer;
          var element = layui.element(),
              laypage = layui.laypage;
          laypage({
					cont: 'page',
					pages: '${page.total}',//总页数
					groups: 3, //连续显示分页数
					curr: '${page.current}' , //固定当前页
				    
					jump: function(obj, first) {
						//得到了当前页，用于向服务端请求对应数据
						var curr = obj.curr;
						//alert(curr+"   1")
						if(!first) {
							//layer.msg('第 '+ obj.curr +' 页');
							//alert(curr+"   1")
							document.forms[0].action="/bsc/systemuser/listUser?curr="+curr;
							document.forms[0].submit();
						}
					}
				});
        //添加文章
  		//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
  	   $(window).one("resize",function(){
  			$(".newsAdd_btn").click(function(){
  				var index = layui.layer.open({
  					title : "添加组织",
  					type : 2,
  					content : "/bsc/systemuser/adduser",
  					success : function(layero, index){
  						setTimeout(function(){
  							layui.layer.tips('点击此处返回文章列表,不自动保存数据 ', '.layui-layer-setwin .layui-layer-close', {
  								tips: 3
  							});
  						},500)
  					}
  				})			
  				layui.layer.full(index);
  			})
  		}).resize();
  	    
      	//查看详情
  		$("body").on("click",".news_collect",function(){  
  			var mobile=$(this).parents("tr").find(".mobile").text();
  			var email=$(this).parents("tr").find(".email").text();
  			var qq=$(this).parents("tr").find(".qq").text();
  			var wechat=$(this).parents("tr").find(".wechat").text();
  			var idno=$(this).parents("tr").find(".idno").text();
  			layer.alert('手机号：'+mobile+'<br/>'+'邮箱：'+email+'<br/>'+'qq号：'+qq+'<br/>'+'微信号：'+wechat+'<br/>'+'身份证号：'+idno,{icon:6, title:'联系方式'});
  		})
  		//  查询
  		//  查询
	   $(".search_btn").click(function(){
			document.forms[0].action="/bsc/systemuser/listUser";
			document.forms[0].submit();
	   });
  	    
  	    
 });
	function up(userid,stat,a){
		layer.confirm('点击确定将会'+a+'此用户！！！',{icon:3, title:'提示信息'},function(index){
 			$.ajax({
	             type: "post",
	             url: "/bsc/systemuser/delUser",
	             data: {'userid':userid,'status':stat},
	             dataType: "json",
	             success: function(data){
	            	 history.go(0);
	             }
	                        
            });
 				layer.close(index);
 			});
	}
    $(function(){
    	 $.post("/bsc/systemuser/listRole",function(msg){
  		   for(i in msg){
  			   $("#role_id").append("<option value="+msg[i].role_id+">"+msg[i].role_name+"</option>");
  		   }
  		  
  	   });
    })
	
   //   给用户角色
   $("body").on("click",".batchDel",function(){
	   var _this=$(this).parents("tr").find(".td").text();
	   $("#user_id").val(_this);
	   $("#myModal").modal("show");
	});
   
   //  提交model数据
   function sub(){
	   $.ajax({
           type: "post",
           url: "/bsc/systemuser/uprole",
           data: $("#f").serialize(),
           dataType: "json",
           success: function(data){
          	 history.go(0);
           }
                      
      }); 
   }
</script>
<!-- Modal -->
<div class="modal fade" id="myModal"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" style="width: 400px">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">角色管理</h4>
      </div>
      <div class="modal-body">
          <form class="form-horizontal" role="form" id="f">
             <input hidden type="text" id="user_id" name="user_id"  />
              <div class="form-group"  >
								<label for="resourcesId" class="col-sm-2 control-label">角色：</label>
								<div class="col-sm-10">
									<select class="form-control" id="role_id" name="role_id">
									  <option value="-1">--请选择--</option>
									</select>
								</div>
			 </div>
          </from>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" onclick="sub()">确认</button>
      </div>
    </div>
  </div>
</div>
</body>
</html>